#include <iostream>
#include <set>
#include <iterator>
using namespace std;

template<class T>
class RuntimeCmp
{
public:
	enum ECmdMode {CM_NORMAL, CM_REVERSE};
private:
	ECmdMode CmdMode;
public:
	RuntimeCmp(ECmdMode m = CM_NORMAL) : CmdMode(m) {}

	bool operator() (const T& lhs, const T& rhs) const {
		return (CmdMode == CM_NORMAL) ? lhs < rhs : rhs < lhs;
	}

	bool operator== (const RuntimeCmp& rc) {
		return CmdMode == rc.CmpMode;
	}	
};

typedef set< int, RuntimeCmp<int> > IntSet;

void Fill(IntSet& set);

int main()
{
	IntSet coll1;
	fill(coll1);
	cout << "coll1: ";
	copy(coll1.begin(), coll1.end(), ostream_iterator<string>(cout, " "));

	RuntimeCmp<int> reverse_order(RuntimeCmp<int>::reverse);

	IntSet coll2(reverse_order);
	Fill(coll2);
	cout << "coll2: ";
	copy(coll2.begin(), coll2.end(), ostream_iterator<string>(cout, " "));
	
	coll1 = coll2;
	coll1.insert(3);
	cout << "coll1: ";
	copy(coll1.begin(), coll2.end(), ostream_iterator<string>(cout, " "));

	if (coll1.value_comp() == coll2.value_comp())
		cout << "coll1 and coll2 have same sorting criterion" << endl;
	else
		cout << "coll1 and coll2 have different sorting criterion" << endl;
	return 0;
}

void Fill(IntSet& set)
{
	set.insert(4);
	set.insert(7);
	set.insert(5);
	set.insert(1);
	set.insert(6);
	set.insert(2);
	set.insert(5);
}

